//
//  SupplyCell.m
//  Rabbit
//
//  Created 阿帕 on 2019/12/12.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "SupplyCell.h"

@interface SupplyCell ()
@property (weak, nonatomic) IBOutlet UILabel *oddNumbersLabel;
@property (weak, nonatomic) IBOutlet UILabel *zhuangAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *xieAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *carInfoLabel;
@property (weak, nonatomic) IBOutlet UIButton *telButton;
@property (weak, nonatomic) IBOutlet UIView *bottomLine;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *stateLabel;
@property (weak, nonatomic) IBOutlet UILabel *branchNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *loadDetailAddressLab;
@property (weak, nonatomic) IBOutlet UILabel *unloadDetailAddressLab;
@property (weak, nonatomic) IBOutlet UIView *lvLine;

@end

@implementation SupplyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _telButton.hidden = YES;
    _branchNameLabel.hidden = YES;
    _branchNameLabel.textColor = Dark_TextColor;
    _oddNumbersLabel.textColor = Dark_TextColor;
    _oddNumbersLabel.adjustsFontSizeToFitWidth = YES;
    _zhuangAddressLabel.textColor = Dark_TextColor;
    _xieAddressLabel.textColor = Dark_TextColor;
    _nameLabel.textColor = Dark_TextColor;
    _carInfoLabel.textColor = Light_TextColor;
    _bottomLine.backgroundColor = BackgroundColor;
    _loadDetailAddressLab.textColor = Dark_TextColor;
    _unloadDetailAddressLab.textColor = Dark_TextColor;
    _lvLine.backgroundColor = Theme_ColorValue;
    
    _branchNameLabel.font = font(15);
    _zhuangAddressLabel.font = font(14);
    _zhuangAddressLabel.numberOfLines = 2;
    _zhuangAddressLabel.adjustsFontSizeToFitWidth = YES;
    _xieAddressLabel.font = font(14);
    _xieAddressLabel.numberOfLines = 2;
    _xieAddressLabel.adjustsFontSizeToFitWidth = YES;
    _nameLabel.font = font(13);
    _carInfoLabel.font = font(11);
    _carInfoLabel.numberOfLines = 2;
    _loadDetailAddressLab.font = font(12);
    _unloadDetailAddressLab.font = font(12);
}

- (void)setSupplyModel:(MainActivityModel *)supplyModel {
    
    _supplyModel = supplyModel;
    if(supplyModel.createdByName.length == 0) {
        _branchNameLabel.text = @"--";

    }else{
        _branchNameLabel.text = CJStringWithFormat(@"发货企业:%@",supplyModel.createdByName);
    }
    _oddNumbersLabel.text = [NSString stringWithFormat:@"货源单号：%@",_supplyModel.mainOrderNumber];
    _zhuangAddressLabel.text = supplyModel.shipperAddress;
    _loadDetailAddressLab.text = supplyModel.shipperDetailAddress;
    _xieAddressLabel.text = supplyModel.consigneeAddress;
    _unloadDetailAddressLab.text = supplyModel.consigneeDetailAddress;
    _nameLabel.text = CJStringWithFormat(@"发货人:%@",supplyModel.shipperName);

//    _stateLabel.hidden = YES;
    [self changeOrderState:supplyModel.pushTarget :supplyModel.isQuote];
    
    NSString *notReceivedCount = @"";
    if (supplyModel.notReceivedCount == 0) {
        notReceivedCount = @"不限车";
    } else {
        notReceivedCount = CJStringWithFormat(@"%ld车",(long)supplyModel.notReceivedCount);
    }
    
    NSString *lastWeight = @"";
    
    if ([DCSpeedy isPureInt:supplyModel.lastWeight]) {
        lastWeight = supplyModel.lastWeight;
    } else {
        lastWeight = CJStringWithFormat(@"%.3f", [supplyModel.lastWeight floatValue]);
    }
    
    if (supplyModel.isQuote == 1) {
        //允许报价，0-不允许，1-允许
        _carInfoLabel.text = CJStringWithFormat(@"%@ %@ %@%@ %@", supplyModel.coalTypeName, notReceivedCount, lastWeight, supplyModel.coalUnitName, [NSString nullToString:supplyModel.pushVehicleUse]);
    } else {
        _carInfoLabel.text = CJStringWithFormat(@"%@ %.2f%@ %@ %@%@ %@", supplyModel.coalTypeName, supplyModel.realPrice, supplyModel.isTrunkName, notReceivedCount, lastWeight, supplyModel.coalUnitName, [NSString nullToString:supplyModel.pushVehicleUse]);
    }
    
//    [_headImageView setImageWithURL:[NSURL URLWithString:_supplyModel.coalName] placeholder:image(@"gcy_img_main_head")];
}
- (IBAction)telButton:(id)sender {
    CALL_PHONE(_supplyModel.shipmentPhone);
}

//判断订单状态
- (void)changeOrderState:(NSString *)pushTarget :(NSInteger)IsQuote {
    /*
     pushTarget 不为空，指派
     pushTarget 空，根据 IsQuote，1竞价，0普通
     */
    if ([DCSpeedy isBlankString:pushTarget] == YES) {
        if (IsQuote == 1) {
            _stateLabel.text = @"竞价单";
            _stateLabel.textColor = [UIColor colorWithHexString:@"#2D7DF6"];
            _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#E7F0FF"];
        } else if (IsQuote == 0) {
            _stateLabel.text = @"普通单";
            _stateLabel.textColor = [UIColor colorWithHexString:@"#04B715"];
            _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#EBF9ED"];
        }
    } else {
        _stateLabel.text = @"指派单";
        _stateLabel.textColor = [UIColor colorWithHexString:@"#EF8221"];
        _stateLabel.backgroundColor = [UIColor colorWithHexString:@"#FEF4EC"];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
